<%@page import="java.util.*" import="java.sql.ResultSet" import="java.sql.Statement" import="java.sql.Connection" import="connection.DBConnection" %> 
<%@page language="java" contentType="text/html; charset=ISO-8859-1"pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Supplier Master Creation</title>

<script language="javascript" type="text/javascript">

function check()
{
	var s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11;
	
  	var namevalid=/^[a-zA-Z ]+$/;
  

        s1= document.f2.suppliername.value;
        if(s1.length==0)
        {
        	alert("Enter Supplier Name");
            return false;
      	}
        else if(s1.search(namevalid)==-1)
        {
            alert("Please Enter valid name");
            document.f.suppliername.value="";
            document.f.suppliername.focus();
            
	         return false;
    	 }
         
         s3= document.f2.supplieraddress.value;
         if(s3.length==0)
         {
              alert("Please Enter Address");
              return false;
          }

	      s4= document.f2.suppliercity.value;
          if(s4.length == 0)
          {
              alert("Please Enter City");
              return false;
          }

         s5= document.f2.supplierstate.value;

         if(s5.length == 0)
         {
              alert("Please Enter State");
              return false;
         }

         s6= document.f2.suppliertin.value;
         if(s6.length == 0)
         {
              alert("Please Enter TIN Number");
              return false;
         }

         s7= document.f2.supplierpan.value;
         if(s7.length == 0)
         {
              alert("Please Enter PAN Number");
              return false;
         }
         var PAN_REGEX= "^([a-zA-Z]){5}([0-9]){4}([a-zA-Z]){1}$";
         
         if(!s7.match(PAN_REGEX))
         {
        	 alert("Please Enter PAN Number in right format. For ex- AAAA1111A")
        	 return false;
         }

         s8= document.f2.suppliermobile.value;
         if(s8.length == 0)
         {
             alert("Please Enter Mobile Number");
             return false;
         }
         
         if(s8.indexOf(" ")!=-1)
    	 {
       		alert("Invalid Mobile No.");
      		return false;
    	 }
    	 else if(s8.length>10)
     	 {
         	alert("Mobile Number should be 10 digit");
       		return false;
     	 }

  /*  	else  if (!(c8.charAt(0)=="9" || c8.charAt(0)=="8" || c8.charAt(0)=="7"))
     	{
        	 alert("Mobile No. should start with 9 or 8 or 7");
       		//  document.getElementById('empcontno').focus();
        	 return false;
     	}
  */
  		else  if (s8.charAt(0)=="0")
		{
  	 		alert("Mobile Number should not start with 0");
 			//  document.getElementById('empcontno').focus();
 			 return false;
		}
  		else if(!(s8.length==10))
     	{
        	 alert("Mobile No. should be 10 digit");
        	// document.getElementById('empcontno').focus();
        	 return false;
     	}
         
         s9= document.f2.supplieremail.value;
         
         var regex = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
         
         if(regex.test(s9) == false)
         {
              alert("Invalid Email Address");
              return false;
          }
   
         s10= document.f2.suppliercontactperson.value;
         if(s10.length==0)
         {
         	alert("Enter Contact Person Name");
             return false;
       	 }
         else if(s10.search(namevalid)==-1)
         {
             alert("Please Enter valid name");
             document.f2.suppliercontactperson.value="";
             document.f2.suppliercontactperson.focus();
             
 	         return false;
     	 }
                 
         s11= document.f2.sopeningbalance.value;
         if(s11.length==0)
         {
         	alert("Enter Opening Balance");
             return false;
       	 }
         if(!s11.match(/^\d+$/))
       	 {
        	 alert("Please Enter Opening balance in Numerics only");
             return false;
       	 }

             return true;
    }
    </script>

</head>

<body>
<form name="f2" action="EditSupplierMasterServlet" ONSUBMIT="return check()">

<%
			String suppliercode=request.getParameter("code1");
			String suppliername=request.getParameter("name1");
			
				 DBConnection dbc=new DBConnection();	
				 Connection con=dbc.getNewConnection();
			
				 Statement st = null;
				 ResultSet rs = null;
				 	 
				 String s1="",s2="",s3="",s4="",s5="",s6="",s7="",s8="",s9="",s10="";
				 double s11=0.0;
			try
			{
			   st=con.createStatement() ;
       		   rs=st.executeQuery("select * from SupplierMaster where scode='"+suppliercode+"' AND sname='"+suppliername+"' "); %>
       		   
       		 <%  while(rs.next()) 
       		 	{ 
       				s1=rs.getString(1);
       				s2=rs.getString(2);
       				s3=rs.getString(3);
       				s4=rs.getString(4);
       				s5=rs.getString(5);
       				s6=rs.getString(6);
       				s7=rs.getString(7);
       				s8=rs.getString(8);
       				s9=rs.getString(9);
       				s10=rs.getString(10);
       				s11=rs.getDouble(11);

            	} %>
  
	 		<% }
		   catch(Exception e){} %>

<table border=0>
	
<tr>
	<th>	</th>
	<th>	</th>
</tr>

<tr>
	<td> Supplier Name </td>
	<td> <input type="text" name="suppliername" value="<%=s2 %>"> </td>
</tr>
<tr>
	<td> Supplier Code </td>
	<td> <input type="text" name="suppliercode" value="<%=s1 %>" > </td>
	
</tr>
	

<tr>
	<td> Address</td>
	<td> <input type="text" name="supplieraddress" value="<%=s3 %>"> </td>
</tr>

<tr>
	<td> City </td>
	<td> <input type="text" name="suppliercity" value="<%=s4 %>"> </td>
</tr>

<tr>
	<td> State </td>
	<td> <input type="text" name="supplierstate" value="<%=s5 %>"> </td>
</tr>

<tr>
	<td> TIN Number </td>
	<td> <input type="text" name="suppliertin" value="<%=s6 %>"> </td>
</tr>

<tr>
	<td> PAN Number</td>
	<td> <input type="text" name="supplierpan" value="<%=s7 %>"> </td>
</tr>

<tr>
	<td> Mobile Number</td>
	<td> <input type="text" name="suppliermobile" value="<%=s8 %>"> </td>
</tr>

<tr>
	<td> Email ID </td>
	<td> <input type="text" name="supplieremail" value="<%=s9 %>"> </td>
</tr>

<tr>
	<td> Contact Person Name </td>
	<td> <input type="text" name="suppliercontactperson" value="<%=s10 %>"> </td>
</tr>

<tr>
	<td> Opening Balance </td>
	<td> <input type="text" name="sopeningbalance"  value="<%=s11 %>"> </td>
</tr>

<tr>
	
	<td align=center colspan=2> <input type="submit" name="enter" value="Submit"> </td>
</tr>

</table>
</form>

</body>
</html>